package network;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

public class TcpEchoClient {
    private Socket socket = null;
    public TcpEchoClient(String serverIP,int serverPort) throws IOException {
        socket = new Socket(serverIP,serverPort);
    }
    public void start() throws Exception {
        Scanner scanner = new Scanner(System.in);
        try (InputStream inputStream = socket.getInputStream();OutputStream outputStream = socket.getOutputStream()){
                PrintWriter writer = new PrintWriter(outputStream);
                Scanner scannerNetwork = new Scanner(inputStream);
                while (true){
                    System.out.print("-->");
                    String request = scanner.next();
                    writer.println(request);
                    writer.flush();
                    String response = scannerNetwork.next();
                    System.out.println(response);
                }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    public static void main(String[] args) throws Exception {
        TcpEchoClient client = new TcpEchoClient("10.0.4.7",9090);
        client.start();
    }
}
